﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Configuration;
using System.Reflection;

namespace devtm.Editor.Configuration.Command
{
    public class CommandHelpers
    {



        public static void HasAddedSection(int index, IElementSection section)
        {
            if (CommandManager.InUndo)
                return;

            CommandAddSection c = new CommandAddSection(index, section);
            Datas.ListeChange.Do(c);
        }


        public static void HasRemovedSection(int index, IElementSection section)
        {
            if (CommandManager.InUndo)
                return;

            CommandRemoveSection c = new CommandRemoveSection(index, section);
            Datas.ListeChange.Do(c);
        }


        public static void 
            HasUpdated(IElementSection section, Object instance, PropertyInfo property, Object oldValue, Object newValue)
        {

            if (CommandManager.InUndo)
                return;

            Command c = new Command(section, TypeChange.Change, instance, property, oldValue, newValue);
            Datas.ListeChange.Do(c);

        }


        public static void HasUpdated(IElementSection section, Object instance, Action Redo, Action Undo)
        {
            if (CommandManager.InUndo)
                return;

            ICommand c = new CommandAction(section, TypeChange.Change, instance, Redo, Undo);
            Datas.ListeChange.Do(c);

        }


        internal static void HasAddedItemToList(IElementSection elementSection, System.Configuration.ConfigurationElement configurationElement, MethodInfo MethodRedo, MethodInfo MethodUndo, object item, TypeChange change)
        {

            if (CommandManager.InUndo)
                return;

            ICommand c = new CommandAddItem(elementSection, configurationElement, MethodRedo, item, MethodUndo, item, change);

            Datas.ListeChange.Do(c);

        }


        internal static void HasAddedItemToList(IElementSection elementSection, System.Configuration.ConfigurationElement configurationElement, MethodInfo MethodRedo, object itemRedo, MethodInfo MethodUndo, object itemUndo, TypeChange change)
        {
            if (CommandManager.InUndo)
                return;

            ICommand c = new CommandAddItem(elementSection, configurationElement, MethodRedo, itemRedo, MethodUndo, itemUndo, change);

            Datas.ListeChange.Do(c);

        }


        internal static void HasAddedItemToList(IElementSection elementSection, System.Configuration.ConfigurationElement configurationElement, 
            MethodInfo MethodRedo,
            System.Configuration.ConfigurationElement itemRedo, 
            Action actionUndo,
            System.Configuration.ConfigurationElement itemUndo, 
            TypeChange change)
        {
            if (CommandManager.InUndo)
                return;

            ICommand c = new CommandAddItemWithAction(elementSection, configurationElement, MethodRedo, itemRedo, actionUndo, itemUndo, change);

            Datas.ListeChange.Do(c);


        }


        internal static void HasCollectionUpdated(IElementSection section, System.Collections.Specialized.NameValueCollection list, string key, string oldValue, string newValue, TypeChange change)
        {

            if (CommandManager.InUndo)
                return;


            ICommand c = new NameValueCollectionCommand(section, list, key, oldValue, newValue, change);
            Datas.ListeChange.Do(c);

        }
    }
}
